#include "stdafx.h"
#include <cv.h>
#include "Matrix3d.h"
#include "MatrixC.h"
#include "iostream"
void display(ostream& out,CvMat* ptr)
{ 
	for (int i=0;i<ptr->rows;i++)
	{
		for (int j=0;j<ptr->cols;j++)
			out<<CV_MAT_ELEM(*ptr,RealT,i,j)<<" ";
		out<<endl;
	}
}
Vector3dC SVD(const Matrix3dC& F,Matrix3dC& U,Matrix3dC& V) 
{
	using namespace std;
	Vector3dC ww;
	//cvSVD(F.matCV,&cvMat(3,1,OPENCV_32FC,&ww.a[0]),U.matCV,V.matCV,CV_SVD_V_T);
	cvSVD(F.matCV,&cvMat(3,1,OPENCV_32FC,&ww.a[0]),U.matCV,V.matCV);
	U*=-1.0f;V*=-1.0f;
	return ww;
}
Vector4dC SVD(const Matrix4dC& F,Matrix4dC& U,Matrix4dC& V) 
{
	Vector4dC ww;
	cvSVD(F.matCV,&cvMat(4,1,OPENCV_32FC,&ww.qu[0]),U.matCV,V.matCV);
	U*=-1.0f;V*=-1.0f;
	return ww;
}
void SolveIP(const Matrix3dC& matt,Vector3dC& ff)
{
	cvSolve(matt.matCV,ff.matCV,ff.matCV);
}
VectorC Solve(MatrixC& MC,VectorC& VC)
{
	VectorC ss(VC.Size());
	cvSolve(MC.matCV,VC.ff,ss.ff);
	return ss;
}

void SVD(const MatrixC& F,MatrixC& U, MatrixC& V) 
{
	VectorC ww(F.matCV->cols);
	if (U.matCV==NULL)
	    U=MatrixC(F.matCV->rows,F.matCV->rows);
	if (V.matCV==NULL)
		V=MatrixC(F.matCV->cols,F.matCV->cols);
	cvSVD(F.matCV,ww.ff,U.matCV,V.matCV);

}